package com.study.manage.dal;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.study.manage.domain.EvaluateApplyTeamUser;
import com.study.manage.domain.User;
import com.study.manage.domain.enumm.EvaluateVerify;


public interface EvaluateApplyTeamUserRepository
        extends PagingAndSortingRepository<EvaluateApplyTeamUser, Long> {

    @Query("select t from EvaluateApplyTeamUser t where t.evaluateApplyId=:evaluateApplyId and t.userId=:userId and t.verify!=2")
    List<EvaluateApplyTeamUser> findByEvaluateApplyIdAndUserIdAndLive(
            @Param("evaluateApplyId") Long evaluateApplyId, @Param("userId") Long userId);


    @Query("select t from EvaluateApplyTeamUser t where t.evaluateApplyId=:evaluateApplyId and t.verify!=2")
    Page<EvaluateApplyTeamUser> findByEvaluateApplyIdAndLive(
            @Param("evaluateApplyId") Long evaluateApplyId, Pageable pageable);

    @Query("select u from EvaluateApplyTeamUser t, User u where u.id=t.userId"
            + " and t.evaluateApplyId=:evaluateApplyId and t.verify=:verify")
    List<User> findUserByEvaluateApplyIdAndVerify(@Param("evaluateApplyId") Long evaluateApplyId,
            @Param("verify") EvaluateVerify verify);

    int countByEvaluateApplyIdAndVerify(Long evaluateApplyId, EvaluateVerify verify);

}
